package java_learn.java_jinjie.DataStructure;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @Author: 李浩然
 * @Date: 2020/12/4 11:35 下午
 */
public class MapTest {
    public static void main(String[] args) {
        HashMap<Character, Integer> map = new HashMap<>();
        System.out.println("请输入字符串");
        String line = new Scanner(System.in).nextLine();
        for (int i = 0; i < line.length(); i++) {
            if (map.containsKey(line.charAt(i))) {
                map.put(line.charAt(i), map.get(line.charAt(i)) + 1);
            } else {
                map.put(line.charAt(i), 1);
            }
        }
        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
            System.out.println("字母" + entry.getKey() + "出现的次数是" + entry.getValue() + "次");
        }
    }
}
